using System;
using UnityEngine;

public class BattleAttack_Siplett_DropletArc : MonoBehaviour
{
	[Header("-= Arc Utility =-")]
	public float JumpArcHeight = 3f;

	public float JumpDuration = 0.5f;

	public bool DisableRandomOffsetMarkiplier;

	[SerializeField]
	private SpriteRenderer BulletSprite;

	[SerializeField]
	private Sprite[] RandomSprites;

	private Vector2 lastPosition;

	[SerializeField]
	private Vector3 JumpStartPos;

	public Vector3 JumpEndPos;

	[SerializeField]
	private float RandomOffsetMarkiplier;

	[SerializeField]
	private AudioClip dropletsound;

	private float timeElapsed;

	private bool isMoving;

	private void Awake()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		BulletSprite.sprite = RandomSprites[Random.Range(0, RandomSprites.Length)];
		BulletSprite.color = new Color(1f, 1f, 1f, 0f);
		CutsceneUtils.FadeInSprite(BulletSprite, 2f);
	}

	private void Start()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		JumpStartPos = ((Component)this).transform.position;
		if (!DisableRandomOffsetMarkiplier)
		{
			JumpEndPos += Vector2.op_Implicit(Random.insideUnitCircle) * RandomOffsetMarkiplier;
		}
		lastPosition = Vector2.op_Implicit(((Component)this).transform.position);
		StartArcMovement();
	}

	private void Update()
	{
		ArcUpdate();
		SetRotationByVelocity();
	}

	private void SetRotationByVelocity()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
		Vector2 val2 = val - lastPosition;
		if (((Vector2)(ref val2)).sqrMagnitude > 0.001f)
		{
			float num = Mathf.Atan2(val2.y, val2.x) * 57.29578f;
			((Component)this).transform.rotation = Quaternion.Euler(0f, 0f, num + 90f);
		}
		lastPosition = val;
	}

	private void ArcUpdate()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		if (isMoving)
		{
			timeElapsed += Time.deltaTime;
			float num = timeElapsed / JumpDuration;
			Vector2 val = CalculateArcPosition(num);
			((Component)this).transform.position = Vector2.op_Implicit(val);
			if (num >= 1f)
			{
				isMoving = false;
				timeElapsed = 0f;
				((Component)this).transform.position = JumpEndPos;
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}

	public void StartArcMovement()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.position = JumpStartPos;
		timeElapsed = 0f;
		isMoving = true;
	}

	private Vector2 CalculateArcPosition(float t)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = Vector2.Lerp(Vector2.op_Implicit(JumpStartPos), Vector2.op_Implicit(JumpEndPos), t);
		float num = JumpArcHeight * Mathf.Sin(MathF.PI * t);
		return new Vector2(val.x, val.y + num);
	}

	private void OnTriggerEnter2D(Collider2D collision)
	{
		if (((Object)((Component)collision).gameObject).name == "Liquid")
		{
			BulletSprite.maskInteraction = (SpriteMaskInteraction)2;
			((Component)this).gameObject.GetComponentInChildren<ParticleSystem>().Stop();
			BattleSystem.PlayBattleSoundEffect(dropletsound, 0.25f);
			Object.Destroy((Object)(object)((Component)this).gameObject, 0.25f);
		}
	}
}
